﻿Public Class CollisionSystem

    ' Contact normal
    ' Contact point
    ' Penetration distance

    ' Structure that stores the results of a Collision
    Public Structure CollisionResult
        ' Are the polygons going to intersect forward in time?
        'Public WillIntersect As Boolean
        ' Are the polygons currently intersecting?
        Public Intersect As Boolean
        ' The translation to apply to the first polygon to push the polygons apart.
        Public MinimumTranslationVector As Vector2
    End Structure


    Structure Axis
        Dim p1 As Point
        Dim p2 As Point
        Dim m As Single

        Function EquationOfTheLine()
            '/ y - y1 = m(x - x1)
            Return 1
        End Function
    End Structure

    Dim Axes() As Axis

    Function Collide(ByVal rectangleA As Rectangle, ByVal rectangleB As Rectangle) As Boolean
        For i = 0 To Axes.Length Step 1
            Dim CurrentAxis As Axis = Axes(i)

            '/Project our shapes now
            'ProjectionA = rectangleA.project(CurrentAxis)
            'ProjectionB = rectangleB.project(CurrentAxis)

            '/Test whether they overlap. Do they?
            'If ProjectionA.overlaps(ProjectionB) = FALSE Then
            ' 'Does we know that anything does not overlap, we know they do not collide.
            Return False
            'End If
        Next

        'We haven't detected the any non-overlaps- therefore it is overlapping
        Return True
    End Function



  
    Public Function RemoveNormalVelocity(ParsedVector As Vector2, angle As Single) As Vector2

        Dim VectoralMomentum As Single = Math.Sqrt(ParsedVector.X ^ 2 + ParsedVector.Y ^ 2)

        Dim Vel_Momentum As Single = VectoralMomentum
        Dim Vel_Angle As Single = MathHelper.WrapAngle(angle)

        Dim Vel_Horizontal As Single = Vel_Momentum * Math.Sin(Vel_Angle) 'MathHelper.ToRadians(Vel_Angle))
        Dim Vel_Normal As Single = Vel_Momentum * Math.Cos(Vel_Angle) 'MathHelper.ToRadians(Vel_Angle))

        Dim NewVectorToReturn As Vector2 = New Vector2(0.5, Vel_Horizontal) '-Vel_Horizontal + Vel_Normal)

        Return NewVectorToReturn
    End Function

    Public Sub DrawLine(graphicsdevice As GraphicsDevice, batch As SpriteBatch, width As Single, color As Color, point1 As Vector2, point2 As Vector2)
        Dim blank As New Texture2D(graphicsdevice, 1, 1, False, SurfaceFormat.Color)
        blank.SetData(New Color() {color.White})

        Dim angle As Single = CSng(Math.Atan2(point2.Y - point1.Y, point2.X - point1.X))
        Dim length As Single = Vector2.Distance(point1, point2)

        batch.Draw(blank, point1, Nothing, color, angle, Vector2.Zero, _
         New Vector2(length, width), SpriteEffects.None, 0)
    End Sub

End Class
